﻿/*var currentItem = [];
var j = 0;
var currentLib;
//used to show approve/reject dialog
function showApproveAll() {
    var ctx = SP.ClientContext.get_current();
    web = ctx.get_web();
    var listId = SP.ListOperation.Selection.getSelectedList();
    var selectedItems = SP.ListOperation.Selection.getSelectedItems(ctx)

    var pageurl =  window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl + "/SitePages/Mapping.aspx";
    var options = {
        url: pageurl,
        args: {
                    listId: listId,
                    selectedItems: selectedItems
                }
        };
        SP.UI.ModalDialog.showModalDialog(options);
    }

//used to determine whether the 'Mapp selection' ribbon will be enalbed or disabled
function enableApprovalAll() {
    var ctx = SP.ClientContext.get_current();
    return SP.ListOperation.Selection.getSelectedItems(ctx).length >= 1;
}
*/


var currentItem = [];
var j = 0;
var currentLib;
//used to show approve/reject dialog
function showApproveAll_Mapping() {
    ctx = SP.ClientContext.get_current();
    web = ctx.get_web();
    site = ctx.get_site();
        
    ctx.load(web);
    ctx.load(site);
    ctx.executeQueryAsync(Function.createDelegate(this, this.onSuccessDelegate_Mapping), Function.createDelegate(this, this.onFailDelegate_Mapping));
    }

    function onSuccessDelegate_Mapping(sender, args) {
   
	listId = SP.ListOperation.Selection.getSelectedList();
	selectedItems = SP.ListOperation.Selection.getSelectedItems(ctx);
	var selectedItems = SP.ListOperation.Selection.getSelectedItems(ctx);
	var SiteCollUrl = getSubString(site.get_url(),'/',3);
	var pageurl = SiteCollUrl + web.get_serverRelativeUrl() + "/SitePages/Mapping.aspx";
		
	var options = {
        url: pageurl,
        args: {
                    listId: listId,
                    selectedItems: selectedItems
                }
        };
        SP.UI.ModalDialog.showModalDialog(options);
    }

    function onFailDelegate_Mapping(sender, args) {
  alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}



//used to determine whether the 'Mapp selection' ribbon will be enalbed or disabled
function enableApprovalAll_Mapping() {
    var ctx = SP.ClientContext.get_current();
    return SP.ListOperation.Selection.getSelectedItems(ctx).length >= 1;
}


function getSubString(str, delimiter, i) 
{
	tokens = str.split(delimiter).slice(0,i),
	result = tokens.join(delimiter);
    return result;
}




